package bairui.international.console.web.controller.prize.nine;

/**
 *
 * ExcelOutput_ExcelExport_ExportOutput
 * excel输出
 */
class ExcelOutput_ExcelExport_ExportOutput

{

	/**
	 * 创建sheet
	 */
	public static com.sh_lianjing.file.excel.write.ExcelWriter createSheet(
		String sheetName,
		java.util.List<Model> list
	) throws Exception{
		return createSheet(sheetName, com.sh_lianjing.file.excel.write.ExcelWriter.newInstanceExcel2007BigData(), list);
	}
	
	public static com.sh_lianjing.file.excel.write.ExcelWriter createSheet(
		String sheetName,
		com.sh_lianjing.file.excel.write.ExcelWriter writer,
		java.util.List<Model> list
	) throws Exception{
		return createSheet(sheetName, writer, Model.class, list, null);
	}

	public static <E extends Model, D> com.sh_lianjing.file.excel.write.ExcelWriter createSheet(
		String sheetName,
		com.sh_lianjing.file.excel.write.ExcelWriter writer,
		Class<E> type,
		java.util.List<E> list,
		D headCommentsData
	) throws Exception{
		return writer
				.createSheet(
					sheetName, 
					type,
					list,
					headCommentsData
				);
	}

	/**
	 * 输出文件
	 */
	public static void output(
		java.util.List<Model> list,
		javax.servlet.http.HttpServletRequest request,
		javax.servlet.http.HttpServletResponse response
	) throws Exception{
		output(
			"中奖", 
			createSheet("中奖", list), 
			request, 
			response
		);
	}

	public static void output(
		String fileName,
		com.sh_lianjing.file.excel.write.ExcelWriter writer,
		javax.servlet.http.HttpServletRequest request,
		javax.servlet.http.HttpServletResponse response
	) throws Exception{
		// 设置格式
		com.lianjing.sh.web.common.util.Util_Web.setDownloadFileName(request, response, fileName+".xlsx");
		response.setContentType(org.springframework.http.MediaType.APPLICATION_XML_VALUE);
		// 生成excel并输出
		try{
			writer.writeTo(response.getOutputStream());
		} finally {
			writer.close();
		};
	}

	
	/**
	 * 排序扩展接口
	 */
	static interface OrderExtends {
		org.springframework.data.domain.Sort gainTitle(
			org.springframework.data.domain.Sort.Direction direction
		);
		org.springframework.data.domain.Sort gainState(
			org.springframework.data.domain.Sort.Direction direction
		);
		org.springframework.data.domain.Sort gainFinishor(
			org.springframework.data.domain.Sort.Direction direction
		);
		
		org.springframework.data.domain.Sort gainId(
			org.springframework.data.domain.Sort.Direction direction
		);
	
		default org.springframework.data.domain.Sort sort(
			org.springframework.data.domain.Sort.Direction direction,
			com.querydsl.core.types.dsl.ComparableExpressionBase<?> ... sortBase
		){
			return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, sortBase);
		}
	
		default com.querydsl.core.types.OrderSpecifier<?> order(
			org.springframework.data.domain.Sort.Direction direction,
			com.querydsl.core.types.dsl.ComparableExpressionBase<?> orderBase
		){
			return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.orderTrans(direction, orderBase);
		}
	}
	
	/**
	 * 排序
	 */
	final static org.springframework.data.domain.Sort sort(
		bairui.international.model.domain.jpa.QTB_WinPrize QRoot,
		javax.servlet.http.HttpServletRequest request
		,OrderExtends orderExtends
	){
		/*
		 * 排序属性
		 */
		// orderBy @RequestParam(name="orderBy", required=false, defaultValue="orderValue") String orderBy
		String orderByPara = request.getParameter(com.lianjing.sh.web.separatepage.OrderInfo.OrderBy);
		if(null == orderByPara){
			orderByPara = "id";
		}
		// orderWay @RequestParam(name="orderWay", required=false, defaultValue="DESC") OrderWay orderWay
		String orderWayPara = request.getParameter(com.lianjing.sh.web.separatepage.OrderInfo.OrderWay);
		if(null == orderWayPara){
			orderWayPara = "DESC";
		}
		org.springframework.data.domain.Sort.Direction direction = org.springframework.data.domain.Sort.Direction.valueOf(orderWayPara);
	
		//
		switch(orderByPara){
			case "title":		return orderExtends.gainTitle(direction);
			case "state":		return orderExtends.gainState(direction);
			case "realName":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.realName);
			case "nickName":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.nickName);
			case "userType":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.userType);
			case "phone":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.phone);
			case "prizeName":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.prizeName);
			case "createTime":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.createTime);
			case "finishFlag":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.finishFlag);
			case "finishTime":		return com.lianjing.sh.spring.web.controller.enhance.output.order.util.Util_Order.sortTrans(direction, QRoot.finishTime);
			case "finishorToString":		return orderExtends.gainFinishor(direction);
			case "id":	return orderExtends.gainId(direction);
			default:
				throw new RuntimeException();
		}
	}
	

	@com.sh_lianjing.file.excel.write.annotation.WriteExcel
	@SuppressWarnings(value="serial")
	abstract 
	public static class Model extends bairui.international.model.domain.jpa.TB_WinPrize{
	
		/**
		 * 构造函数
		 */
		@lombok.Getter @com.fasterxml.jackson.annotation.JsonIgnore
		private bairui.international.model.domain.jpa.TB_WinPrize _origin;
	
		public Model(
			bairui.international.model.domain.jpa.TB_WinPrize bean
		) {
			this._origin = bean;
			if(null != bean){
				this.setRealName(bean.getRealName());
				this.setNickName(bean.getNickName());
				this.setUserType(bean.getUserType());
				this.setPhone(bean.getPhone());
				this.setPrizeName(bean.getPrizeName());
				this.setCreateTime(bean.getCreateTime());
				this.setFinishFlag(bean.getFinishFlag());
				this.setFinishTime(bean.getFinishTime());
				this.setFinishor(bean.getFinishor());
			}
			/* 附加属性赋值前 */
			assign_before();
			/* 附加属性赋值 */
			this.setTitle(this.assignTitle());
			this.setState(this.assignState());
		}
		
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(1)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "活动标题")
		/** get[活动标题] */
		public String getTitle() {
			return this.title;
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(2)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "活动状态")
		/** get[活动状态] */
		public bairui.international.model.status.State_Prize getState() {
			return this.state;
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(3)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "用户真实姓名")
		
		@Override
		public String getRealName() {
			return (String)super.getRealName();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(4)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "用户昵称")
		
		@Override
		public String getNickName() {
			return (String)super.getNickName();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(5)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "用户类型")
		
		@Override
		public bairui.international.model.type.Type_User getUserType() {
			return (bairui.international.model.type.Type_User)super.getUserType();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(6)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "用户电话")
		
		@Override
		public String getPhone() {
			return (String)super.getPhone();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(7)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "奖品名称")
		
		@Override
		public String getPrizeName() {
			return (String)super.getPrizeName();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(8)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelDateFormat(pattern = "yyyy-MM-dd")
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "抽奖时间")
		
		@Override
		public java.util.Date getCreateTime() {
			return (java.util.Date)super.getCreateTime();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(9)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "核销标志")
		
		@Override
		public Boolean getFinishFlag() {
			return (Boolean)super.getFinishFlag();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(10)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelDateFormat(pattern = "yyyy-MM-dd")
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "核销时间")
		
		@Override
		public java.util.Date getFinishTime() {
			return (java.util.Date)super.getFinishTime();
		}
		
		@com.sh_lianjing.reflect.method.annotation.MethodOrder(11)
		@com.sh_lianjing.file.excel.write.annotation.WriteExcelCell(comment = "核销者")
		public String getFinishorToString() {
			bairui.international.model.domain.jpa.TB_Admin it = this.getFinishor();
			if(null != it){
				return it.toString();
			}
			return null;
		}
		
		
		/**
		 * 非继承属性
		 */
		abstract protected void assign_before();
		
		/** 活动标题 */
		 @lombok.Setter 
		private String title;
		/** 赋值活动标题 */
		abstract protected String assignTitle();
	
		/** 活动状态 */
		 @lombok.Setter 
		private bairui.international.model.status.State_Prize state;
		/** 赋值活动状态 */
		abstract protected bairui.international.model.status.State_Prize assignState();
	
		/**
		 * 相关类
		 */
	}
	

}

